package com.demo.resourcecode.c14boot;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
@Import({TestSelector.class, TestSelector2.class, ImportBeanDefinitionRegistrarTest.class})
@ConditionalOnProperty(prefix = "study", name = "enable", havingValue = "true")
public class ConditionConfig {

	// 注意看studyEnable的初始化顺序
	@Value("${study.enable}")
	private boolean studyEnable;
	@Autowired
    private DubboConfigurationProperties dubboConfigurationProperties;

	public ConditionConfig(){
		// init condition：false
		System.out.println("init condition：" + studyEnable);
	}

	@Bean
	@ConfigurationProperties(DubboConfigurationProperties.targetName)
	public DubboConfigurationProperties dubboConfigurationProperties(){
		return new DubboConfigurationProperties();
	}

	@Bean
	public String aa(){
		// aa：true
		System.out.println("aa：" + studyEnable);
		System.out.println(dubboConfigurationProperties().getApplication());
		System.out.println(dubboConfigurationProperties().getAddress());
		return "aa";
	}

	@Bean
	public CacheableAdvice cacheableAdvice(){
		return new CacheableAdvice();
	}

}
